import Vue from 'vue'
import constants from './constants'
var global = {
  allowUploadFormats(type) {
    var map = new Map()
    map.set('image', 'png,jpg,jpeg')
    map.set('audio', 'mp3')
    map.set('video', 'swf,flv,mp4,wav,avi')
    map.set('word', 'doc,docx,xls,xlsx,ppt,pptx,txt,pdf')
    map.set('zip', 'rar,zip')
    map.set('file', '*')
    return map.get(type)
  },
  getFileView(uuid) {
    if (uuid) {
      if (uuid && (uuid.indexOf('http://') === 0 || uuid.indexOf('https://') === 0)) {
        return uuid
      } else {
        return `${process.env.NODE_ENV === 'development' ? process.env.VUE_APP_BASE_API : window.g.baseURL}fileView/${uuid}?AppId=${constants.APP_ID}&AppKey=${constants.APP_KEY}&ProjectsId=${constants.PROJECTS_ID}`
      }
    } else {
      return '-1'
    }
  },
  handleFilePreview(uuid) {
    window.open(this.getFileView(uuid))
  }
}

Vue.prototype.global = global
export default global
